
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class PageViewServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String path = request.getSession().getServletContext().getRealPath("/");
		File f1=new File(path+File.separator+"PV.txt");
		if(!f1.exists()){
			f1.createNewFile();
		}
		BufferedReader br=new BufferedReader(new FileReader(f1));
		String s1 = br.readLine();
		br.close();
		Integer i=0;
		try{
			 i=Integer.parseInt(s1);
		}catch(Exception e){
			
		}
		i++;
		writeS(""+i, f1);
	}

	public void writeS(String str, File file) {
		char[] cuf = str.toCharArray();// 将指定的字串序列化为byte[]
		try {
			OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file));
			out.write(cuf);
			out.flush();
			out.close();
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}
